import DList from "@/components/dlist";
export default {
  data() {
    return {
      showPopover: false,
      actions: [
        { text: "技师" , id: 1},
      ],
      actions_name: "需求",
      name: "",
      myLocation: {},
      dataList: [],
      loading: false,
      finished: false,
      page: 1
    };
  },
  activated() {
    this.actions_name = this.$route.params.name ?  this.$route.params.name : '需求';
    this.myLocation = JSON.parse(localStorage.getItem("myLocation"));
    this.init();
    this.getData();
  },
  methods: {
    init(){
      this.dataList = [];
      this.loading = false;
      this.finished = false;
      this.page = 1;
    },
    onSelect(val) {
      this.actions_name = val.text;
      this.actions = [{ text: val.text ==  '需求' ? "技师" : "需求", id: val.text ==  '需求' ? 1 : 2}];
      this.init();
      this.getData();
    },
    onOpen() {
      this.actions = [{ text: this.actions_name ==  '需求' ? "技师" : "需求", id: this.actions_name ==  '需求' ? 1 : 2}];
    },
    async getData() {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let url = this.actions_name == '需求' ? 'plugin.be-within-call.frontend.public-search.need-order' : 'plugin.be-within-call.frontend.public-search.shifu'
      let { data, result, msg } = await $http.get(url, { 
        lng: this.myLocation ? this.myLocation.point.lng : "",
        lat: this.myLocation ? this.myLocation.point.lat : "",
        name: this.name,
        page_size: 15,
        page: this.page
      });
      if (result === 0) {
        this.$toast(msg);
        return;
      }
      if (data.data.length === 0 || data.data.length < data.per_page || data.current_page === data.last_page) {
        this.finished = true;
      }
      this.total = data.total;
      this.dataList.push(...data.data);
      this.page++;
      this.loading = false;
    },
    inputValue() {
      console.log(11111);
      this.init();
      this.getData();
    },
    onLoad() {
      this.getData();
    },
    goDetailPage(id,type) {
      if(type == '需求') {
        this.$router.push(
          this.fun.getUrl("anytimeIndividualNeeds", {type:1 , order_id: id})
        );
      }else if(type == '技师') {
        this.$router.push(
          this.fun.getUrl("anytimeTechnicianHome", { id })
        );
      }
    }
  },
  components: { DList }
};
